package com.jxc.jxcmanage.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import com.jxc.jxcmanage.code.entity.Account;
import com.jxc.jxcmanage.code.entity.UserInfo;
import com.jxc.jxcmanage.code.mapper.AccountMapper;
import com.jxc.jxcmanage.code.mapper.ProductMapper;
import com.jxc.jxcmanage.common.ResultBean;
import com.jxc.jxcmanage.constants.Constant;
import com.jxc.jxcmanage.dto.CustomerDto;
import com.jxc.jxcmanage.dto.MaterialDto;
import com.jxc.jxcmanage.dto.MaterialUsageDto;
import com.jxc.jxcmanage.dto.ProductDto;
import com.jxc.jxcmanage.dto.ProductInventoryDto;
import com.jxc.jxcmanage.dto.ProfitAmountDto;
import com.jxc.jxcmanage.dto.SupplierDto;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
@EnableScheduling
@Service
public class ServiceForTest {
	@Autowired
	private AccountMapper accountMapper;
	@Autowired
	private ProductMapper productMapper;
	@Autowired
	private ProductService productService;
	@Autowired
	private CustomerService customerService;
	@Autowired
	private SupplierService supplierService;
	@Autowired
	private UserInfoService userInfoService;
	@Autowired
	private ProductInventoryService productInventoryService;
	@Autowired
	private ProfitAmountService profitAmountService;
	@Autowired
	private MaterialService materialService;
	@Autowired
	private MaterialUsageService materialUsageService;
	private int count = 1;

	private static final Logger LOGGER = LoggerFactory.getLogger(ServiceForTest.class);
	//@Scheduled(fixedRate = 2000)
	public void test() {
		Account record = new Account();
		record.setDepartment(1);
		record.setStatus(1);
		record.setAccount("index");
		record.setCreatedBy("123");
		record.setUpdatedBy("456");
		record.setCreatedDate(new Date());
		record.setUpdatedDate(new Date());
		accountMapper.insert(record);
	}
//	@Scheduled(fixedRate = 12000)
	public void testProduct() {
		int size = 5;
		List<ProductDto> dtos = new ArrayList<>();
		ProductDto dto = new ProductDto();
		dto.setStatus(1);
		dto.setCreatedBy("2");
		dto.setUpdatedBy("5");
		dto.setCreatedDate(new Date());
		dto.setUpdatedDate(new Date());
		dto.setName("测试");
		dto.setNote("55");
		dto.setCode("123456");
		dto.setSpecs("ceshi");
		dto.setUnit("525");
		dtos.add(dto);
		List<ProductDto> list = productMapper.list(dto);
//		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(dto));
		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(list));
		productMapper.insertBatch(dtos);
		dto.setPageNumber(count);
		dto.setPageSize(size);
		count = count ++;
		ResultBean resultBean = productService.page(dto);
		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(resultBean.getData()));

	}
//	@Scheduled(fixedRate = 2000)
	public void testCustomer() {
		int size = 5;
		List<CustomerDto> params = new ArrayList<>();
		CustomerDto dto = new CustomerDto();
		dto.setStatus(1);
		dto.setCreatedBy("2");
		dto.setUpdatedBy("5");
		dto.setCreatedDate(new Date());
		dto.setUpdatedDate(new Date());
		dto.setName("测试");
		dto.setNote("55");
		params.add(dto);
		customerService.csvImport(params);
//		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(dto));
//		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(list));
		dto.setPageNumber(count);
		dto.setPageSize(size);
		count = count ++;
		ResultBean resultBean = customerService.page(dto);
		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(resultBean.getData()));
	}
//	@Scheduled(fixedRate = 12000)
	public void testSupplier() {
		int size = 20;
		List<SupplierDto> params = new ArrayList<>();
		SupplierDto dto = new SupplierDto();
		dto.setStatus(1);
		dto.setCreatedDate(new Date());
		dto.setUpdatedDate(new Date());
		dto.setNote("55");
		dto.setName("毛衣制造供应商");
		dto.setCode("123");
		dto.setCityCode("");
		dto.setCreatedBy("1515");
		dto.setUpdatedBy("565656");
		params.add(dto);
		supplierService.csvImport(params);
//		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(dto));
//		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(list));
		dto.setPageNumber(count);
		dto.setPageSize(size);
		count = count ++;
		ResultBean resultBean = supplierService.page(dto);
		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(resultBean.getData()));
	}
//	@Scheduled(fixedRate = 2000)
	public void testlogin() {
		UserInfo userInfo = new UserInfo();
		userInfo.setUserCode("123" + System.currentTimeMillis());
		userInfo.setCreatedBy("32432");
		userInfo.setUpdatedBy("4353");
		userInfo.setUpdatedDate(DateUtil.format(new Date(), Constant.TIME));
		userInfo.setCreatedBy(DateUtil.format(new Date(), Constant.TIME));
		userInfo.setUserDesc("测试");
		userInfo.setUserName("index");
		userInfo.setUserPassword("4r34tq34");
		userInfoService.addOrUpdateUserInfo(userInfo);
		UserInfo resultBean = userInfoService.findByCode(userInfo);
		LOGGER.info("......:{}.....", JSONUtil.toJsonStr(resultBean));
	}
	//@Scheduled(fixedRate = 12000)
	public void testProductInventory() {
		ProductInventoryDto productInventory = new ProductInventoryDto();
		productInventory.setCreatedBy("32432");
		productInventory.setUpdatedBy("4353");
		productInventory.setUpdatedDate(new Date());
		productInventory.setSold(10);
		productInventory.setTotal(3);
		productInventory.setSurplus(4);
		productInventory.setSupplierId(1L);
		productInventory.setProductId(4L);
		productInventoryService.save(productInventory);
		productInventory.setCreatedDate(new Date());
		productInventory.setId(1L);
		productInventoryService.update(productInventory);
		productInventoryService.list(productInventory);
	}
	//@Scheduled(fixedRate = 12000)
	public void testProfitAmount() {
		ProfitAmountDto productInventory = new ProfitAmountDto();
		productInventory.setAccountId(2L);
		productInventory.setStatisticsType("PDT");
		productInventory.setCreatedBy("32432");
		productInventory.setUpdatedBy("4353");
		productInventory.setCreatedDate(new Date());
		productInventory.setSaleDate("20210512");
		productInventory.setAmount(new BigDecimal(10));
		productInventory.setSupplierId(1L);
		productInventory.setProductId(4L);
		profitAmountService.save(productInventory);
		productInventory.setUpdatedDate(new Date());
		productInventory.setId(1L);
//		profitAmountService.update(productInventory);
		profitAmountService.list(productInventory);
	}

	// @Scheduled(fixedRate = 12000)
	public void testMaterial() {
		MaterialDto dto = new MaterialDto();
		dto.setCode("BL0112");
		dto.setSpecs("40*40CM");
		dto.setUnit("块");
		dto.setName("雨伞布");
		dto.setCreatedBy("32432");
		dto.setUpdatedBy("4353");
		dto.setCreatedDate(new Date());
		dto.setSupplierId(1L);
		materialService.save(dto);
		dto.setUpdatedDate(new Date());
		// profitAmountService.update(productInventory);
		materialService.list(dto);
	}

	//@Scheduled(fixedRate = 12000)
	public void testMaterialUsage() {
		MaterialUsageDto dto = new MaterialUsageDto();
		dto.setCreatedBy("32432");
		dto.setUpdatedBy("4353");
		dto.setCreatedDate(new Date());
		dto.setUsage(2);
		dto.setMaterialId(5L);
		dto.setProductId(4L);
		materialUsageService.save(dto);
		dto.setUpdatedDate(new Date());
		dto.setId(1L);
		// profitAmountService.update(productInventory);
		materialUsageService.list(dto);
	}
}
